<%@page import="com.lanju.enums.ShopType"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" session="false"%>
<%@ include file="/WEB-INF/view/common/loginCheck.jspf" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<link rel="stylesheet" type="text/css" href="${ROOT}/static/js/easyui/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="${ROOT}/static/js/easyui/themes/icon.css" />
</head>	

<body>	
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',title:'门店列表'" style="padding:5px">
    	<table id="shopDataList" style="width:99%;height:100%"></table>
		<div id="shopToolbar">
			<div style="padding:3px;">
				状态：<select class="easyui-combobox" id="statusSelectBox">
				 	<option value="">--选择状态--</option>
				 	<option value="-1">不通过</option>
                	<option value="0">待审</option>
                	<option value="1">通过</option>
				</select>
				类型：<input id="typeSelectBox" style="width:250px;" name="type" value="" />
				区域：<input id="areaSelectBox" style="width:250px;" name="area" value="" />
				<input class="easyui-searchbox" id="shopSearchBox" data-options="prompt:'店名、联系人、电话、区域名', searcher:searchShop" style="width:30%" />
			</div>
			<div>
				<t:permission codes="SHOP-AUDIT">
				<a href="javascript:void(0)" title="通过" class="easyui-linkbutton" iconCls="icon-ok" plain="true" onclick="statusShop(1)">通过</a>
			    <a href="javascript:void(0)" title="不通过" class="easyui-linkbutton" iconCls="icon-no" plain="true" onclick="statusShop(-1)">不通过</a>
			    </t:permission>
		    </div>
		</div>
    </div>
</div>

<script type="text/javascript" src="${ROOT}/static/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="${ROOT}/static/js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ROOT}/static/js/easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${ROOT}/static/js/common/common.js"></script>
<script type="text/javascript">
	var status = '';
	var type = '';
	var areaId = '';
	$(function () {
		$('#shopDataList').datagrid({
		    url:'${ROOT}/shop/listAudit?_rt=' + new Date().getTime(),
		    columns:[[
				{field: 'id', width: '10%', checkbox: true, align: 'left'},
				{field: 'pathSl', width: '10%', title: '图片', align: 'left', formatter:function(value, row, index) {
					return '<img width="50px" height="50px" src="<%=SysPropCacheManager.getPropValue("oss.imageAccessUrl")%>/' + value + '" />';	
				}},
		        {field: 'name', title: '名称', width: '200', align: 'left'},
		        {field: 'areaName', title: '区域', width: '200', align: 'left'},
		        {field: 'typeName', title: '类型', width: '200', align: 'left'},
		        {field: 'contact', title: '联系人', width: '200', align: 'left'},
		        {field: 'tel', title: '电话', width: '200', align: 'left'},
		        {field: 'address', title: '地址', width: '200', align: 'left'},
		        {field: 'username', title: '所属业务员', width: '200', align: 'left'},
		        {field: 'status', title: '状态', width: '50', align: 'center',
		        	formatter:function(value, row, index) {
		        		var color = 'green';
		        		var name = '通过';
		        		if (value == 0) {
		        			color = 'gray';
		        			name = '待审';
		        		} else if (value == -1) {
		        			color = 'red';
		        			name = '不通过';
		        		}
			        	return '<font color="' + color + '"><b>' + name + '</b></font>';		        			
		            }
		        },
		        {field: 'createdTime', title: '创建时间', width: '130', align: 'left'},
		        {field: 'updatedTime', title: '更新时间', width: '130', align: 'left'}
		    ]],
		    idField: 'id',
		    toolbar: '#shopToolbar',
	    	rownumbers: true,
	    	pagination: true,
	    	pageSize: 20,
	    	singleSelect: false,
	    	checkOnSelect: true,
	    	scrollbarSize: 12,
	    	onDblClickRow: function (index, row) {
	    		
	    	}
		});
		
		$('#statusSelectBox').combobox({
		    onSelect: function (node) {
		    	status = node.value;
		    	searchShop();
		    }
		});
		$('#typeSelectBox').combobox({
			url:'${ROOT}/shop/shoptype?_rt=' + new Date().getTime(),
		    valueField:'type',
		    textField:'name',
		    onSelect: function (node) {
		    	type = node.type;
		    	searchShop();
		    }
		});
		$('#areaSelectBox').combobox({
			url:'${ROOT}/area/listAll?_rt=' + new Date().getTime(),
		    valueField:'id',
		    textField:'name',
		    onSelect: function (node) {
		    	areaId = node.id;
		    	searchShop();
		    }
		});
	});
	
	function searchShop() {
		$('#shopDataList').datagrid('load', {
		    keyword: $.trim($('#shopSearchBox').searchbox('getValue')),
		    status: status,
		    type: type,
		    areaId: areaId
		});
		$('#shopDataList').datagrid('clearSelections');
    	$('#shopDataList').datagrid('clearChecked');
	}
	
	function statusShop(sts) {
		status = sts;
		var selectedRows = $('#shopDataList').datagrid('getSelections');
		if (selectedRows == null ||selectedRows.length <= 0) {
			APP.warning('请选择要审核的门店');
			$('#statusChangeBox').combobox("setValue", '');
			return;
		}
		var msg = '你确定要审核选中的门店吗?';
		APP.confirm(msg, function (flag) {
			if (flag) {
				var ids = '';
				for (var i = 0; i < selectedRows.length; i++) {
					if (i > 0) {
						ids += ',';
					}
					ids += selectedRows[i].id;
				}
				APP.post({
					url: '${ROOT}/shop/status?_rt=' + new Date().getTime(),
					data: {
						ids: ids,
						status: status
					},
					success: function (data) {
						var success = data.success;
						var msg = data.msg;
						if (success == undefined) {
							var json = eval('(' + data + ')');
							success = json.success;
							msg = json.msg;
						}
						if (success) {
							$('#shopDataList').datagrid('reload');
							APP.message('审核成功');
							$('#shopDataList').datagrid('clearSelections');
				        	$('#shopDataList').datagrid('clearChecked');
				        	$('#statusChangeBox').combobox("setValue", '');
						} else {
							APP.error(msg);
						}
					}
				});
			}
		});
	}
</script>
</body>
</html>